package cn.huhst.cas.weisiqian.pojo;

import cn.huhst.cas.weisiqian.util.JSON;

public class News {

	private int newsid;
	private String title;
	private String content;
	private String author;
	private java.sql.Date writetime;
	private int viewcount;

	/**
	 * 新闻标题由汉字，大小写字母，数字，“-”，“.”,“ ”组成,长度不超过20
	 */
	private static String titleRegx = "^([\\u4e00-\\u9fa5]|[0-9a-zA-Z]|-|.| ){1,20}$";
	/**
	 * 新闻内容由汉字，大小写字母，数字，“-”，“.”,“ ”组成
	 */
	private static String contentRegx = "^([\\u4e00-\\u9fa5]|[0-9a-zA-Z]|-|.| )*?$";
	/**
	 * 新闻作者由2到5个汉字组成或者由4到10个词字符组成（词字符：大小写字母和数字）
	 */
	public static final String authroRegx = "^([\\u4e00-\\u9fa5]{2,5})|([a-zA-Z0-9]{4,10})$";

	public JSON checkTitleFormat(String title, JSON json) {
		if (title == null || !title.matches(titleRegx)) {
			json.put("title", "新闻标题由汉字，大小写字母，数字，“-”，“.”,“ ”组成,长度不超过20");
		}
		return json;
	}

	public JSON checkContentFormat(String content, JSON json) {
		if (content == null || !content.matches(contentRegx)) {
			json.put("content", "新闻内容由汉字，大小写字母，数字，“-”，“.”,“ ”组成");
		}
		return json;
	}

	public JSON checkAuthroFormat(String author, JSON json) {
		if (author == null || !author.matches(authroRegx)) {
			json.put("author", "新闻作者由2到5个汉字组成或者由4到10个词字符组成（词字符：大小写字母和数字）");
		}
		return json;
	}

	public JSON checkFormat() {
		JSON json = new JSON();
		json = checkTitleFormat(title, json);
		json = checkContentFormat(content, json);
		json = checkAuthroFormat(author, json);
		return json;
	}

	public int getNewsid() {
		return newsid;
	}

	public void setNewsid(int newsid) {
		this.newsid = newsid;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public java.sql.Date getWritetime() {
		return writetime;
	}

	public void setWritetime(java.sql.Date writetime) {
		this.writetime = writetime;
	}

	public int getViewcount() {
		return viewcount;
	}

	public void setViewcount(int viewcount) {
		this.viewcount = viewcount;
	}

	@Override
	public String toString() {
		return "News [newsid=" + newsid + ", title=" + title + ", content=" + content + ", author=" + author
				+ ", writetime=" + writetime + ", viewcount=" + viewcount + "]";
	}

}
